package coder814.Login.controller;

import coder814.User.entity.User;
import coder814.User.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by 来自北海的风 on 2017/8/14.
 */

@Controller
@RequestMapping("login")
public class LoginController {

    private UserService userServiceImpl;
    @Autowired
    public LoginController(UserService userServiceImpl){
        this.userServiceImpl=userServiceImpl;
    }
    @RequestMapping
    public String login(){

        return "login";
    }
    @RequestMapping("/check")
    @ResponseBody
    public String checkLogin(HttpServletRequest request){

        String username=request.getParameter("username");
        String password=request.getParameter("password");

        User user=userServiceImpl.findUserByUserName(username);

        if(user!=null){
            if(password.equals(user.getPassword())){
                return "login_succ";
            }else{
                return "login_fail";
            }
        }else {
            return "login_fail";
        }




    }
}
